//package com.source.code.demo;
//
//import static com.source.code.ClassInfoToJsonApp.getJsonString;
//
//import com.github.javaparser.JavaParser;
//import com.github.javaparser.ParseResult;
//import com.github.javaparser.ast.CompilationUnit;
//import com.github.javaparser.ast.body.MethodDeclaration;
//import com.github.javaparser.ast.expr.MethodCallExpr;
//
//import com.source.code.model.MethodChildInfo;
//import com.source.code.model.MethodInfo;
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.IOException;
//import java.util.ArrayList;
//import java.util.List;
//
//public class JavaCodeAnalyzer {
//
//    public static void main(String[] args) {
//        String projectPath = System.getProperty("user.dir");
//        List<MethodInfo> methodInfos = analyzeProject(projectPath);
//
//        // Convert methodInfos to JSON
//        LogUtil.printf(getJsonString(methodInfos));
//    }
//
//    private static List<MethodInfo> analyzeProject(String projectPath) {
//        List<MethodInfo> methodInfos = new ArrayList<>();
//
//        // Recursively analyze all Java files in the project
//        analyzeJavaFiles(new File(projectPath), methodInfos);
//
//        return methodInfos;
//    }
//
//    private static void analyzeJavaFiles(File file, List<MethodInfo> methodInfos) {
//        if (file.isDirectory()) {
//            File[] files = file.listFiles();
//            if (files != null) {
//                for (File subFile : files) {
//                    analyzeJavaFiles(subFile, methodInfos);
//                }
//            }
//        } else if (file.getName().endsWith(".java")) {
//            analyzeJavaFile(file, methodInfos);
//        }
//    }
//
//    private static void analyzeJavaFile(File file, List<MethodInfo> methodInfos) {
//        try (FileInputStream fileInputStream = new FileInputStream(file)) {
//            JavaParser parser = new JavaParser();
//            ParseResult<CompilationUnit> parse = parser.parse(fileInputStream);
//            CompilationUnit compilationUnit = parse.getResult().orElseThrow(() -> new RuntimeException("Parsing error"));
//
//            // Extract methods and their calls
//            compilationUnit.findAll(MethodDeclaration.class).forEach(method -> {
//                String className = compilationUnit.getPrimaryTypeName().orElse("");
//                String methodName = method.getNameAsString();
//                List<MethodChildInfo> calledMethods = extractCalledMethods(method);
//                MethodInfo methodInfo = new MethodInfo();
//                methodInfo.setClassAllName(className);
//                methodInfo.setMethodAllName(methodName);
//                methodInfo.setChildMethodAllNames(calledMethods);
//                methodInfos.add(methodInfo);
//            });
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//    private static List<MethodChildInfo> extractCalledMethods(MethodDeclaration method) {
//        List<MethodChildInfo> calledMethods = new ArrayList<>();
//
//        method.walk(node -> {
//            if (node instanceof MethodCallExpr) {
//                MethodCallExpr callExpr = (MethodCallExpr) node;
//                String methodName = callExpr.getNameAsString();
//                MethodChildInfo methodChildInfo = new MethodChildInfo().setSimpleName(methodName);
//                calledMethods.add(methodChildInfo);
//            }
//        });
//
//        return calledMethods;
//    }
//}
